#include<bits/stdc++.h>
using namespace std;
#define int long long

int f[200005];

signed main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> f[i];

	for (int i = 1; i <= n; i++) {
		if (f[i - 1] + f[i] >= 0)
			f[i] += f[i - 1];
	}
	cout << *max_element(f + 1, f + n + 1);
	return 0;
}
